#include "../inc/hr_manager.h"

int hr_login_verify(trans_usrinfo_t *recv_info, sqlite3 *db)
{
    char usrname[32] = {0};
    char password[32] = {0};
    strcpy(usrname, recv_info->usrname);
    strcpy(password, recv_info->password);
    login_info_t login_info;
    strcpy(login_info.usrname, usrname);
    strcpy(login_info.password, password);
    login_info.if_true = 0;
    if (db_verify(db, login_info))
    {
        // 登录成功
        return 1;
    }
    else
    {
        // 登录失败
        return 0;
    }
}

staff_info_t get_staff_info(char *recv_info) // 也可以用规定数据块的大小来打包
{
    staff_info_t staff_info;
    char name[32] = {0};
    int old = 0;
    char old_s[5] = {0};
    char department[32] = {0};
    int salary = 0;
    char salary_s[10] = {0};
    int i = 0;
    char *res = strtok(recv_info, " "); // 自己封装的话 持续遍历 到空格的时候
    while (res != NULL)
    {
        switch (i)
        {
        case 0:
            strcpy(name, res);
            break;
        case 1:
            strcpy(old_s, res);
            break;
        case 2:
            strcpy(department, res);
            break;
        case 3:
            strcpy(salary_s, res);
            break;
        default:
            break;
        }
        i++;
        res = strtok(NULL, " ");
    }

    old = atoi(old_s);
    salary = atoi(salary_s);
    strcpy(staff_info.name, name);
    staff_info.old = old;
    strcpy(staff_info.department, department);
    staff_info.salary = salary;
    return staff_info;
}

int manager_login_verify(trans_usrinfo_t *recv_info, sqlite3 *db)
{
    char usrname[32] = {0};
    char password[32] = {0};
    strcpy(usrname, recv_info->usrname);
    strcpy(password, recv_info->password);
    login_info_t login_info;
    strcpy(login_info.usrname, usrname);
    strcpy(login_info.password, password);
    login_info.if_true = 0;
    if (db_verify_manager(db, login_info))
    {
        // 登录成功
        return 1;
    }
    else
    {
        // 登录失败
        return 0;
    }
}